package dancrawler.client.gamecmd;

import dancrawler.common.Misc;
import dancrawler.client.Client;
import dancrawler.client.GameObject;
import dancrawler.proto.cmd.CmdHandler;
import dancrawler.server.Gameworld;
import dancrawler.proto.cmd.NetCommand;
import dancrawler.server.netMsg;

/**
 *
 */
public class CmdUpdatePos extends CmdHandler {
    private Client client;
    public CmdUpdatePos(Client client)
    {
        this.client = client;
    }

    @Override
    public int getNumArgs() {
        return 3;
    }

    @Override
    public int getArgSize(int n) {
        int[] argsize = {2, 2, 2};
        if(n > getNumArgs()-1)
        {
            return 0;
        }
        return argsize[n];
    }

    @Override
    public void handleCmd(netMsg msg) {
        int x = Misc.bytesToShort(msg.getArgs()[0]);
        int y = Misc.bytesToShort(msg.getArgs()[1]);
        int oid = Misc.bytesToShort(msg.getArgs()[2]);
        GameObject obj = client.getObjectRegister().getGameObject(oid);
        client.getWorld().setObjPos(obj, x, y);
    }

    @Override
    public CmdHandler getHandler() {
        return this;
    }

    @Override
    public int getId() {
        return 1;
    }

}
